package com.vcar.LDiceServer.filter;

//import java.util.zip.InflaterInputStream;
import java.io.DataInputStream;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

import com.vcar.LDiceServer.vo.RequestMessage;

import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Input;

//import com.vcar.LDiceServer.vo.UserVO;
public class AMF3Decoder extends CumulativeProtocolDecoder
{
	private final SerializationContext context = new SerializationContext();
	private final Amf3Input amf3in;

	public AMF3Decoder()
	{
		amf3in = new Amf3Input(context);
	}

	@Override
	protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception
	{
		// UserVO uo = UserManager.instance().get(session);
		amf3in.setInputStream(new DataInputStream(in.asInputStream()));
		Object message = amf3in.readObject();
		if (message instanceof RequestMessage)
		{
			out.write(message);
			in.free();
			return true;
		} else
		{
			in.free();
			return false;
		}
	}
}
